<?php
if(!isset($_SESSION['logged']) OR $_SESSION['logged'] !== TRUE){
	header('Location: index.php?page=login');
}else{
	require_once VIEW_DIR.'/menuAdmin.php';

	echo '<div id="content">';
	if(isset($_GET['mod'])){
		switch($_GET['mod']){
			case 'news':
				require_once MODEL_DIR.'/NewsModel.php';
				$oNewsInstance = new NewsModel();

				if(isset($_GET['action']) AND !empty($_GET['action'])){
					switch($_GET['action']){
						case 'add':
							require_once CONTROLLER_DIR.'/newsAddController.php';
						break;
						case 'del':
							require_once CONTROLLER_DIR.'/newsDelController.php';
						break;
						case 'edit':
							require_once CONTROLLER_DIR.'/newsEditController.php';
						break;
					}
				}
			break;
			case 'devNotes':
				require_once MODEL_DIR.'/DevNotesModel.php';
				$oDevNotesInstance = new DevNotesModel();

				if(isset($_GET['action']) AND !empty($_GET['action'])){
					switch($_GET['action']){
						case 'add':
							require_once CONTROLLER_DIR.'/devNotesAddController.php';
						break;
						case 'del':
							require_once CONTROLLER_DIR.'/devNotesDelController.php';
						break;
						case 'edit':
							require_once CONTROLLER_DIR.'/devNotesEditController.php';
						break;
					}
				}
			break;
			case 'project':
				require_once MODEL_DIR.'/ProjectModel.php';
				$oProjectInstance = new ProjectModel();

				if(isset($_GET['action']) AND !empty($_GET['action'])){
					switch($_GET['action']){
						case 'add':
							require_once CONTROLLER_DIR.'/projectAddController.php';
						break;
						case 'del':
							require_once CONTROLLER_DIR.'/projectDelController.php';
						break;
						case 'edit':
							require_once CONTROLLER_DIR.'/projectEditController.php';
						break;
					}
				}
			break;
			case 'todo':
				require_once MODEL_DIR.'/TodoListModel.php';
				$oTodoInstance = new TodoListModel();

				if(isset($_GET['action']) AND !empty($_GET['action'])){
					switch($_GET['action']){
						case 'add':
							require_once CONTROLLER_DIR.'/todoListAddTaskController.php';
						break;
						case 'edit':
							require_once CONTROLLER_DIR.'/todoListEditTaskController.php';
						break;
						case 'del':
							require_once CONTROLLER_DIR.'/todoListDelTaskController.php';
						break;
					}
				}else{
					require_once MODEL_DIR.'/TodoListModel.php';
					$aiassTasksList = $oTodoInstance->getTasks();
					require_once VIEW_DIR.'/homeAdmin.php';
				}
			break;
			default:
				if(file_exists(CONTROLLER_DIR.'/'.$_GET['mod'].'Controller.php')){
					require_once CONTROLLER_DIR.'/'.$_GET['mod'].'Controller.php';
				}
			break;
		}
	}else{
		require_once MODEL_DIR.'/TodoListModel.php';
		$oTodoInstance = new TodoListModel();
		$aiassTasksList = $oTodoInstance->getTasks();
		require_once VIEW_DIR.'/homeAdmin.php';
	}
	echo '</div>';
}
